<div id="cms_sidebarIndex">
<?php

//	include_once("cmsConfig.php");
	
	$authInfo = extractObjectWithKeyFromArray('authInfo', $_SESSION);
	
//	if (!is_null($authInfo)  ){
	if (false) {
	
        $altAdd = "Add New Record";
        $altList = "List Current Content";
        
		$db = extractObjectWithKeyFromArray('db', $GLOBALS);
		        
		$formDescriptorTableWriter = new TableWriter( "formdescriptor", $db );//where the fuck does the db ... not come from//
		$formDescriptorTableWriter->resetCustomIterator(" WHERE contentmodule=1 AND activemodule=1 AND sidebarmodule=1  AND (" . $_SESSION['viewMode'] . " & modeaccess)");
?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td colspan="5"><img src="/cms/images/spacer.gif" width="8" height="20" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td colspan="2" valign="top" class="cms_sidebartext"><img src="/cms/images/icon_home.gif" width="28" height="24" /></td>
            <td valign="top" class="cms_sidebartext">
              <a href="/cms/html/index.php?fileNo=13">Home</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext" colspan="2"><a href="./index.php?fileNo=14"><img src="/cms/images/pwchange_icon.gif" alt="change passowrd" /></a></td>

            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=14">Change P/word</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="12" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="16" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="83" height="8" border="0" /></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <?
			if ($_SESSION['viewMode'] === '4' ) {
				if ($authInfo->usertype === '0' ) {
          ?>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=9">
                <img src="/cms/images/add.gif" width="12" height="12" border="0" alt="Add New User" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=7">
                <img src="/cms/images/list.gif" width="16" height="12" border="0" alt="View Users" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=7">Users</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=10">
                <img src="/cms/images/add.gif" width="12" height="12" border="0" alt="Add New Group" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=8">
                <img src="/cms/images/list.gif" width="16" height="12" border="0" alt="View Groups" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=8">Groups</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=5">
                <img src="/cms/images/add.gif" width="12" height="12" border="0" alt="Add New Form" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=6">
                <img src="/cms/images/list.gif" width="16" height="12" border="0" alt="View Forms" />
              </a>
            </td>
            <td valign="top" class="cms_sidebartext">
              <a href="./index.php?fileNo=6">Forms</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <?
				}
			}

		if ( $formDescriptorTableWriter->db->numRows()>0 ){	
?>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="12" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="16" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="83" height="8" border="0" /></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>

          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="16" border="0" /></td>
            <td colspan="3" valign="top" class="cms_sidebartext"><b>MODULES</b></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          
<?php
		}
	
		while ($row = $formDescriptorTableWriter->nextItem()) {
		// We need to test if the module should show in this viewmode
		// if(viewFormAuth($row->modeaccess)) {
		
			//we need a away to look up the document code also.. farking fark.
?>
          
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext">
              <? if (addFormAuth($authInfo, $row, null, $db)) {?>
              <a href="./index.php?fileNo=2&formId=<?= $row->formid ?>">
                <img src="/cms/images/add.gif" width="12" height="12" border="0" alt="<?= $altAdd; ?>" />
              </a>
              <? } else {?>
              <img src="/cms/images/spacer.gif" width="12" height="12" border="0" />
              <? } ?>
            </td>
            <td valign="top" class="cms_sidebartext">
              <? if (viewFormAuth($authInfo, $row, null, $db)) {?>
              <a href="./index.php?fileNo=1&formid=<?= $row->formid ?>&sorts=clear&direction=clear">
                <img src="/cms/images/list.gif" width="16" height="12" border="0" alt="<?= $altList; ?>" />
              </a>
              <? } else {?>
              <img src="/cms/images/spacer.gif" width="12" height="12" border="0" />
              <? } ?>
            </td>
            <td valign="top" class="cms_sidebartext">
              <? if (viewFormAuth($authInfo, $row, null, $db)) {?>
              <a href="./index.php?fileNo=1&formid=<?= $row->formid ?>&sorts=clear&direction=clear"><?= $row->formname ?></a>
              <? } else {?>
              <?= $row->formname ?>
              <? } ?>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
<?php
		//close the logic for permission to view in this mode for this formid
		//}
		}
		
		//echo "viewMode = ". $_SESSION['viewMode']. " <br>";
		$query = " Where contentmodule=0 AND activemodule=1 AND sidebarmodule=1 AND (" . $_SESSION['viewMode'] . " & modeaccess) ";
		$formDescriptorTableWriter = new CmsTableWriter( "formdescriptor", $db );
		$formDescriptorTableWriter->resetCustomIterator($query);
		
		// need to require the db to pull out on the appropriate forms depending on the mode
		// use bitwise operators eg & for and get permission constants to compare with and create a query
		// $query = " Where contentmodule=0 AND activemodule=1 AND sidebarmodule=1 AND (" . $_SESSION['viewMode'] . " & modeaccess)";
	
		if ( $formDescriptorTableWriter->db->numRows()>0 ){
		
	
?>          
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="12" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="16" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="83" height="8" border="0" /></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="16" border="0" /></td>
            <td colspan="3" valign="top" class="cms_sidebartext"><b>CODE TABLES</b></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
<?php

		}

	
		while ($row = $formDescriptorTableWriter->nextItem()) {
	
?>
          
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext">
              <? if (addFormAuth($authInfo, $row, null, $db)) {?>
              <a href="./index.php?fileNo=2&formId=<?= $row->formid ?>">
                <img src="/cms/images/add.gif" width="12" height="12" border="0" alt="<?= $altAdd; ?>" />
              </a>
              <? } else {?>
              <img src="/cms/images/spacer.gif" width="12" height="12" border="0" />
              <? } ?>
            </td>
            <td valign="top" class="cms_sidebartext">
              <? if (viewFormAuth($authInfo, $row. null, $db)) {?>
              <a href="./index.php?fileNo=1&formid=<?= $row->formid ?>&sorts=clear&direction=clear">
                <img src="/cms/images/list.gif" width="16" height="12" border="0" alt="<?= $altList; ?>" />
              </a>
              <? } else {?>
              <img src="/cms/images/spacer.gif" width="12" height="12" border="0" />
              <? } ?>
            </td>
            <td valign="top" class="cms_sidebartext">
              <? if (viewFormAuth($authInfo, $row, null , $db)) {?>
              <a href="./index.php?fileNo=1&formid=<?= $row->formid ?>&sorts=clear&direction=clear"><?= $row->formname ?></a>
              <? } else {?>
              <?= $row->formname ?>
              <? } ?>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
<?php          
		}     
?>
          
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="12" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="16" height="8" border="0" /></td>
            <td valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="83" height="8" border="0" /></td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0"></td>
          </tr>
          
          <tr> 
            <td><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td colspan="2" valign="top" class="cms_sidebartext"><img src="/cms/images/icon_logout.gif" width="28" height="24" /></td>
            <td valign="top" class="cms_sidebartext">
              <a href="./cmsLogout.php">Logout</a>
            </td>
            <td><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          
          <tr> 
            <td width="12"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td width="12" valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="12" height="8" border="0" /></td>
            <td width="16" valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="16" height="8" border="0" /></td>
            <td width="83" valign="top" class="cms_sidebartext"><img src="/cms/images/spacer.gif" width="83" height="8" border="0" /></td>
            <td width="12"><img src="/cms/images/spacer.gif" width="10" height="8" border="0" /></td>
          </tr>
          
        </table>
<?
	}
?>
</div>